//
//  EpointInputViewController.m
//  EpointFrame5
//
//  Created by 李亚春 on 14-2-25.
//  Copyright (c) 2014年 Epoint. All rights reserved.
//

#import "EpointInputViewController.h"

@interface EpointInputViewController ()
{
    UITextView *utv;
}
@end

@implementation EpointInputViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    if (!CurrentDeviceISiPad) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
    }
    
    
    utv = [[UITextView alloc]initWithFrame:[self getFullContentFrame]];
    [self.view addSubview:utv];
    [utv setFont:[UIFont systemFontOfSize:22]];
    utv.text = [self.passParam objectForKey:@"preContent"];
    utv.delegate = self;
    [utv becomeFirstResponder];
    [self setRightBarButtonItemWithTitle:@"确定" action:@selector(submit)];
}

- (void) keyboardWasShown:(NSNotification *) notif{
    NSDictionary *info = [notif userInfo];
    NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGSize keyboardSize = [value CGRectValue].size;
    [utv setFrame:CGRectMake(0, 0, AppWidth, UIViewRemain-keyboardSize.height)];
}


-(void)submit
{
//    if (utv.text==nil||[@"" isEqualToString:[utv.text stringByReplacingOccurrencesOfString:@" " withString:@""]]) {
//        [self toastMessage:@"请填写反馈内容!"];
//        return ;
//    }
    //处理ipad确定成功后，关闭界面 edit by wangzhigang at 2014-07-03 周四 15:06
    if (CurrentDeviceISiPad) {
        NSArray* arr=self.navigationController.viewControllers;
        NSLog(@"count=%i",arr.count);
        [self.navigationController popViewControllerAnimated:YES];
        if (arr.count==1) {
            EpointPhoneViewController* backVc =[arr objectAtIndex:0];
            [backVc popBack];
        }
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
    self.inputSubmitHandler(utv.text);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

+(void)involeInputViewController:(UIViewController *)vc vctitle:(NSString *)vctitle preContent:(NSString*)preContent handler:(InputSubmitHandler)handler
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
    [params setObject:vctitle forKey:@"title"];
    [params setObject:preContent forKey:@"preContent"];
    EpointInputViewController *im = [[EpointInputViewController alloc]init];
    im.inputSubmitHandler = handler;
    im.passParam = params;
    [vc.navigationController pushViewController:im animated:YES];
}

@end
